import java.util.Scanner;

public class java4 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入第一个字符串：");
        String str1 = scanner.nextLine();

        System.out.println("请输入第二个字符串：");
        String str2 = scanner.nextLine();

        String common = findcommon(str1, str2);
        System.out.println("相同的最长的字符串为：" + common);
    }

    public static String findcommon(String str1, String str2) {
        String common = "";
        int maxLength = 0;

        for (int i = 0; i < str1.length(); i++) {
            for (int j = i + 1; j <= str1.length(); j++) {
                String subStr = str1.substring(i, j);
                if (str2.contains(subStr) && subStr.length() > maxLength) {
                    maxLength = subStr.length();
                    common = subStr;
                }
            }
        }

        return common;
    }
}
